-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using tsl.lux can produce unanticipated Exception #17
Conversation
using tsl.lux without consideration of all possible values will eventually produce an unanticipated Exception. return values can be a float, 0, or None. implicit datatype handling provides float(0) == 0.0 but float(None) will produce an Exception. alternatively, one should check isinstance( tsl.lux, Float ) but that would not explicitly show tsl.lux can be None in this example.
is it happy now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. One more question about it.
If we change this: lux = 0. Then returns would either be a float or None. Checking would still need to be done for None, but that is a general issue with any sensor that may return None to indicate a bad reading. For example, this could also potentially throw an unexpected exception: if tsl.lux > SOME_THRESHOLD:
print("bright light! bright light!") when trying to do a comparison with None. In general, the simpletest examples assume goodness so the code can be brief. Adding that conditional check isn't too much though, if you think having it would help. Instead of saying it's a NaN or None, could also say something like "bad sensor reading" in the print. @tannewt What would be the additional info? Are you thinking just docstring or something in actual code? |
i encountered this issue because of using %0.1f to format the value of lux. 'as built', python is very forgiving about 0.0 versus 0 but if you want to be very lint-y then, yes, it ought to be 0.0 to skip the implicit datatype conversion in code using this module. |
the Exception due to None being returned was a surprise (to me) since the docs didn't say anything about the lux method not returning a float when taking readings using the default gain and integration time while logging the diurnal cycle at a rural north-facing window. dark sky abounds here at night. |
@caternuson I meant in the property docstring. More details in the threaded conversation. |
proposed changes
Thanks @csylvain and @caternuson |
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x to 1.10.1 from 1.10: > Merge pull request adafruit/Adafruit_CircuitPython_ADXL34x#7 from siddacious/master Updating https://github.com/adafruit/Adafruit_CircuitPython_AM2320 to 1.1.3 from 1.1.2: > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#7 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#6 from adafruit/pylint-version-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_APDS to 1.2.3 from 1.1.2: > Merge pull request adafruit/Adafruit_CircuitPython_APDS#11 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_APDS#10 from adafruit/pylint-version-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_BME680 to 3.0.7 from 3.0.6: > Merge pull request adafruit/Adafruit_CircuitPython_BME680#15 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_BME680#14 from robert-hh/master Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO055 to 3.0.5 from 3.0.4: > Merge pull request adafruit/Adafruit_CircuitPython_BNO055#19 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_BNO055#18 from adafruit/pylint-version-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_CCS811 to 1.1.4 from 1.1.3: > Merge pull request adafruit/Adafruit_CircuitPython_CCS811#27 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_CCS811#26 from caternuson/iss25 Updating https://github.com/adafruit/Adafruit_CircuitPython_CharLCD to 3.1.0 from 3.0.3: > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#27 from kattni/add-buttons > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#25 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_DS2413 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_DS2413#8 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_FocalTouch#5 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_FXAS21002C to 1.2.2 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_FXAS21002C#7 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_FXOS8700 to 1.2.2 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_FXOS8700#10 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_HCSR04 to 0.3.4 from 0.3.3: > Merge pull request adafruit/Adafruit_CircuitPython_HCSR04#8 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_HCSR04#7 from adafruit/readme-image-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_HTU21D to 0.8.1 from 0.8.0: > Merge pull request adafruit/Adafruit_CircuitPython_HTU21D#3 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 3.3.1 from 3.3.0: > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#20 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#18 from fmorton/master Updating https://github.com/adafruit/Adafruit_CircuitPython_L3GD20 to 2.0.2 from 2.0.1: > Merge pull request adafruit/Adafruit_CircuitPython_L3GD20#11 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_LIDARLite to 1.1.1 from 1.1.0: > Merge pull request adafruit/Adafruit_CircuitPython_LIDARLite#3 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH to 4.3.4 from 4.3.3: > Merge pull request adafruit/Adafruit_CircuitPython_LIS3DH#49 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM303 to 1.2.3 from 1.2.2: > Merge pull request adafruit/Adafruit_CircuitPython_LSM303#10 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1 to 2.0.2 from 2.0.1: > Merge pull request adafruit/Adafruit_CircuitPython_LSM9DS1#14 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX31855 to 3.0.5 from 3.0.4: > Merge pull request adafruit/Adafruit_CircuitPython_MAX31855#9 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX31865 to 2.1.2 from 2.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_MAX31865#8 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP4725 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_MCP4725#6 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP9808 to 3.2.2 from 3.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_MCP9808#15 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MLX90614 to 1.1.1 from 1.1.0: > Merge pull request adafruit/Adafruit_CircuitPython_MLX90614#10 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MMA8451 to 1.2.2 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_MMA8451#4 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MPL3115A2 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_MPL3115A2#4 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_MPRLS to 1.0.3 from 1.0.2: > Merge pull request adafruit/Adafruit_CircuitPython_MPRLS#5 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_NeoTre to 1.04 from 1.0.3: > Merge pull request adafruit/Adafruit_CircuitPython_NeoTre#4 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 to 3.2.4 from 3.2.3: > Merge pull request adafruit/Adafruit_CircuitPython_PCA9685#18 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_PCF8523 to 1.2.2 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_PCF8523#8 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_Pixie to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_Pixie#6 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_Se to 1.2.7 from 1.2.6: > Merge pull request adafruit/Adafruit_CircuitPython_Se#22 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_Se#21 from adafruit/pylint-version-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_SGP30 to 2.0.1 from 2.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_SGP30#14 from Dmole/patch-1 > Merge pull request adafruit/Adafruit_CircuitPython_SGP30#13 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_SI4713 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_SI4713#6 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_SI5351 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_SI5351#3 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_SI7021 to 3.1.2 from 3.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_SI7021#10 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_STMPE610 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_STMPE610#7 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_TCA9548A to 0.1.2 from 0.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_TCA9548A#4 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_TLC5947 to 1.2.1 from 1.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_TLC5947#12 from ArthurDent62/negative_indices > Merge pull request adafruit/Adafruit_CircuitPython_TLC5947#13 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_TLC59711 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_TLC59711#4 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_TSL2561 to 3.1.3 from 3.1.2: > Merge pull request adafruit/Adafruit_CircuitPython_TSL2561#18 from caternuson/float_doc > Merge pull request adafruit/Adafruit_CircuitPython_TSL2561#21 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_TSL2561#17 from csylvain/patch-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_VCNL4010 to 0.9.2 from 0.9.1: > Merge pull request adafruit/Adafruit_CircuitPython_VCNL4010#5 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_VEML6070 to 2.0.1 from 2.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_VEML6070#6 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_VEML6075 to 1.0.2 from 1.0.1: > Merge pull request adafruit/Adafruit_CircuitPython_VEML6075#3 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_VL53L0X to 3.1.5 from 3.1.4: > Merge pull request adafruit/Adafruit_CircuitPython_VL53L0X#8 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_WS2801 to 0.9.2 from 0.9.1: > Merge pull request adafruit/Adafruit_CircuitPython_WS2801#3 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_AVRprog to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_AVRprog#6 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_BoardTest to 1.0.1 from 1.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_BoardTest#4 from ShawnHymel/master > Merge pull request adafruit/Adafruit_CircuitPython_BoardTest#3 from ShawnHymel/master Updating https://github.com/adafruit/Adafruit_CircuitPython_Debouncer to 1.0.2 from 1.0.1: > Merge pull request adafruit/Adafruit_CircuitPython_Debouncer#6 from dastels/Dans_suggestions Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 0.8.1 from 0.8.0: > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#4 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_miniQR to 1.1.1 from 1.1.0: > Merge pull request adafruit/Adafruit_CircuitPython_miniQR#4 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_Register to 1.3.3 from 1.3.2: > Merge pull request adafruit/Adafruit_CircuitPython_Register#18 from sommersoft/readme_fix_travis > Merge pull request adafruit/Adafruit_CircuitPython_Register#17 from adafruit/pylint-version-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_RTTTL to 2.2.2 from 2.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_RTTTL#11 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_ServoKit to 1.0.3 from 1.0.2: > Merge pull request adafruit/Adafruit_CircuitPython_ServoKit#5 from kattni/multiple-servo-examo Updating https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_SimpleIO#37 from sommersoft/readme_fix_travis Updating https://github.com/adafruit/Adafruit_CircuitPython_Waveform to 1.2.2 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_Waveform#5 from sommersoft/readme_fix_travis
using tsl.lux without consideration of all possible values will eventually produce an unanticipated Exception.
return values can be a float, 0, or None.
implicit datatype handling provides float(0) == 0.0 but float(None) will produce an Exception.
alternatively, one should check isinstance( tsl.lux, Float ) but that would not explicitly show tsl.lux can be None in this example.